<template>
	<view class="sub-appeal-content">
		<view class="home-top">
			<view class="home-title">下单流程</view>
			<image src="../../../static/common/sub-back-icon.png" class="sub-back-icon" @tap="backpage"></image>
			<image src="../../../static/common/sbu-home-top-icon.png" class="sub-home-top-icon" @tap="contactKF"></image>
		</view>
		
		<view class="make-order-tip">
			<view>1. 遇到任何问题请回到超级返联系客服，切勿旺旺咨询商家</view>
			<view>2. 下单完成后，切记第一时间复制订单号返回超级返，回填 订单号</view>
			<view>3. 严谨使用任何返利软件下单购买，违反者从返款中扣除返 利所得，严重者封号处理。</view>
		</view>
		<image src="../../../static/common/make-gift-btn.png" class="make-gift-btn" @tap="backpage"></image>
		<!-- 商品信息 -->
		<view class="goods-info">
			<view class="info-text">目标商品信息</view>
			<view class="info-detail">
				<image src="../../../static/common/img-mask.png" class="img-mask"></image>
				<image :src="taskInfo.imageUrl?getImg(taskInfo.imageUrl) : '../../../static/common/make-order-good-img.png'" class="good-img"></image>
				<view class="detail-right">
					<view>店铺名：{{taskInfo.shopName}}</view>
					<view style="margin-top: 7upx;"><text>实拍价：￥{{taskInfo.productActualPrice}}    应返：￥{{calculate(taskInfo.productActualPrice,taskInfo.giftPrice)}}</text></view>
					<view style="margin: 7upx 0 45upx 0;width: 100%;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
						搜索关键词：{{taskInfo.keyword?taskInfo.keyword:"暂无关键词"}}</view>
					<view v-if="taskInfo.orderMethod!=0">按照  "<text>{{getSort(taskInfo.orderMethod)}}</text>"  排序</view>
				</view>
			</view>
		</view>
		<!-- 商家要求 -->
		<view class="requirement" style="margin-bottom: 20upx;" v-if="taskInfo.isTaojinbi || taskInfo.isYouhuiquan || taskInfo.isHuabei">
			<view class="info-text" style="padding-left: 0;">商家额外要求</view>
			<view class="ext-rul">{{taskInfo.isTaojinbi && taskInfo.isTaojinbi == 1 ? "不要使用淘金币!" : ""}}</view>
			<view class="ext-rul">{{taskInfo.isYouhuiquan && taskInfo.isYouhuiquan == 1 ? "不要使用店铺优惠券!" : ""}}</view>
			<view class="ext-rul">{{taskInfo.isHuabei && taskInfo.isHuabei == 1 ? "不要使用分期、花呗、信用卡!" : ""}}</view>
		</view>
		
		<!-- 商家备注 -->
		<view class="requirement">
			<view class="info-text" style="padding-left: 0;">商家备注</view>
			<view class="req-text">{{taskInfo.remark?taskInfo.remark:"暂无备注..."}}</view>
		</view>
		
		<!-- 下单帮助 -->
		<view class="make-help">
			<view class="help-text">1. 复制关键词打开淘宝搜索</view>
			<view class="help-text">2. 找到与目标商品、主图、店铺名、价格一致的商品完成下单</view>
			<view class="help-text">3. 下单完成后复制淘宝该订单编号，返回超级返进行回填提交</view>
			<view class="attention">（若不确定是否为目标商品，长按复制该商品标题，此处验证）</view>
		</view>
		<view class="verification">
		<!-- 	<view class="order-number">{{goodsURL}}</view>
			<view class="paste" @tap="pastText">一键粘贴验证</view> -->
			<view class="order-number">{{goodsName}}</view>
			<view class="paste" @tap="pastGoodsName">一键粘贴验证</view>
		</view>
		<!-- 填写回单 -->
		<view class="huian">
			<view class="opentao-btn" @tap="searchKeyWord">复制关键词打开淘宝</view>
			<view class="huidan-btn" @tap="writeOrder">回填订单号</view>
		</view>
	</view>
</template>

<script>
	export default{
		name:"subAppeal",
		data(){
			return{
				apptoken:"",
				taskInfo:"",
				goodsURL:"",
				goodsName:"",
				taskId:"",
			}
		},
		onLoad(options) {
			console.log(options)
			this.taskId = options.taskId;
			console.log(options.taskId);
			this.apptoken = uni.getStorageSync("apptoken");
			this.getOrder();
		},
		methods:{
			calculate(productActualPrice,giftPrice){
				//return Number(productActualPrice) - Number(giftPrice);
				return (Number(productActualPrice)*1000 - Number(giftPrice)*1000)/1000;
			},
			searchKeyWord(){
				//搜索关键词
				if(!this.taskInfo.keyword){
					uni.showModal({
						title:"温馨提示",
						content:"该商品暂无搜索关键词，请根据其他商品信息去淘宝搜索目标商品",
						showCancel:false,
					})
				}else{
					uni.setClipboardData({
					    data: this.taskInfo.keyword,
					    success: function () {
								//#ifdef APP-PLUS
									//判断是否安装淘宝
									if(plus.runtime.isApplicationExist({pname:'com.taobao.taobao',ction:"taobao://"})){
										console.log("淘宝应用已安装");
										if ( plus.os.name == "Android" ) {
												plus.runtime.launchApplication( {pname:"com.taobao.taobao"}, function ( e ) {
														uni.showModal({
															title:"温馨提示",
															content:"app无法打开手机淘宝,请尝试手动打开",
															showCancel:false,
														})
												});
											} else if ( plus.os.name == "iOS" ) {
												plus.runtime.launchApplication( {action:"taobao://"}, function ( e ) {
													uni.showModal({
														title:"温馨提示",
														content:"app无法打开手机淘宝,请尝试手动打开",
														showCancel:false,
													})
												});
											}
									}else{
										console.log("淘宝应用未安装");
										plus.runtime.openWeb("http://www.taobao.com");
									}
								//#endif
					    }
					});
				}
			},
			getImg(img){
				return this.$CommonJS.getBaseImgUrl(img)
			},
			getSort(n){
				//排序 1是销量 2是综合 3是直通车 4是价格
				switch(n){
					case 1:
						return '销量';
						break;
					case 2:
						return '综合';
						break;
				}
			},
			pastText(){
				//粘贴链接
				this.goodsURL = "";
				//console.log(111)
				const _this = this;
				uni.getClipboardData({
					success: function (res) {
						_this.goodsURL = res.data;
						//验证链接
						console.log(res)
						if(res.data == ""){
							uni.showModal({
								title:"温馨提示",
								content:"请复制商品链接,再点击核实",
								showCancel:false,
							})
						}else{
							if(res.data!==_this.taskInfo.productUrl){
								uni.showModal({
									title:"温馨提示",
									content:"商品核实错误,可能原因是：1.找错商品，请按照页面说明重新查找。2.复制的信息不符合商品链接，请重新复制",
									showCancel:false,
								})
							}else{
								uni.showToast({
									title:"商品核对成功"
								})
							}
						}
						
					},
					fail(res) {
						_this.$CommonJS.showToast("请复制商品链接验证")
					}
				});
			},
			pastGoodsName(){
				//验证商品标题
				this.goodsName = "";
				const _this = this;
				uni.getClipboardData({
					success: function (res) {
						_this.goodsName = res.data;
						//验证链接
						console.log(res)
						if(res.data == ""){
							uni.showModal({
								title:"温馨提示",
								content:"请复制商品标题,再点击核实",
								showCancel:false,
							})
						}else{
							const id1 = decodeURI( _this.$CommonJS.getUrlParam(res.data)['id']);
							const id2 = decodeURI( _this.$CommonJS.getUrlParam(_this.taskInfo.productUrl)['id']);
							if(id1 != id2){
								uni.showModal({
									title:"温馨提示",
									content:"商品核实错误,可能原因是：1.找错商品，请按照页面说明重新查找。2.复制的信息不符合商品标题，请重新复制",
									showCancel:false,
								})
							}else{
								uni.showToast({
									title:"商品核对成功"
								})
							}
						}
						
					},
					fail(res) {
						_this.$CommonJS.showToast("请复制商品标题验证")
					}
				});
			},
			getOrder(){
				//任务详情
				const _this = this;
				uni.request({
					url:this.$API.URL + this.$API.task_view,
					data:{apptoken:this.apptoken,customerTaskId:this.taskId},
					success(res) {
						console.log(res);
						if(res.data.success){
							_this.taskInfo = res.data.data;
						}else{
							_this.$CommonJS.showToast(res.data.msg);
						}
					}
				})
			},
			writeOrder(){
				//回单
				//const _this = this;
				this.$CommonJS.navigateTo('../../subBack/sub-fillorder/sub-fillorder?customertaskId='+this.taskId);
				// uni.showModal({
				// 	title:"温馨提示",
				// 	content:this.$CommonJS.content,
				// 	success(res) {
				// 		if(res.confirm){
				// 			_this.$CommonJS.navigateTo('../../subBack/sub-fillorder/sub-fillorder?customertaskId='+_this.taskId);
				// 		}
				// 	}
				// })
			},
			backpage(){
				this.$CommonJS.navigateBack();
			},
			contactKF(){
				this.$CommonJS.navigateTo('../../subBack/sub-kefu/sub-kefu')
			}
		}
	}
</script>

<style scoped>
	@import url("sub-makeorder.css");
</style>
